<?php
// 本类由系统自动生成，仅供测试用途
class IndexAction extends Action {
    public function index(){
        /*$this->assign('cp_jj',i18n::load()->trans('公司简介'));
    	$this->assign('sv_jj',i18n::load()->trans('服务内容'));
    	$this->assign('tel_jj',i18n::load()->trans('联系我们'));
    	$this->assign('pd_jj',i18n::load()->trans('产品展示'));
    	
    	$this->assign('cp_jj_nr',i18n::load()->trans('公司简介内容'));
    	$this->assign('pd_jj_nr',i18n::load()->trans('产品展示内容'));
    	$this->assign('sv_jj_nr',i18n::load()->trans('服务内容内容'));
    	$this->assign('tel_jj_nr',i18n::load()->trans('联系我们内容'));
    	*/
    	/*if($_SESSION["MENUS"]){
    		$out=$_SESSION["MENUS"];
    	}else{
    		$out=$this->getMenu();
    	}
    	*/
    	
    	
    
    	/*$rel[1]=i18n::load()->trans('公司简介内容');
    	$rel[2]=i18n::load()->trans('产品展示内容');
    	$rel[3]=i18n::load()->trans('墙体彩绘内容');
    	$rel[4]=i18n::load()->trans('服务内容内容');
    	$rel[5]=i18n::load()->trans('联系我们内容');
    	$this->assign('nr',$rel);
    	*/
    	/*$out=$this->getMenu();
    	$menu=new Model("menu");
    	$data=$menu->select();
    	$neirong=array();
    	if(count($data)){
    		foreach ($data as $val){
    			$nr=stripslashes($val["m_text_cn"]);
    			if($_SESSION["lan"]=='en'){
    				$nr=stripslashes($val["m_text_en"]);
    			}
    			$nr=str_replace('&nbsp;', '', $nr);
    			$neirong[$val['m_id']]=cut_str($nr,50);
    		}
    	}
    	
    	$this->assign('nr',$neirong);
    	
    	//$_SESSION["MENUS"]=$out;
    	$this->assign("menu",$out);
		//http://www.zgyjys.com
	 */
		$this->display("index");
    }
    /**
     * 设置多语
     */
    public function language(){
    	$lan=$_REQUEST["lan"];
    	$url=$_REQUEST["url"];
    	//Session("lan",$lan);
    	$_SESSION["lan"]=$lan;
    	$_url="/?m=Index&a=index";
    	if($url=="cp"){
    		$_url="/?m=Index&a=cp";
    	}
    	//$this->redirect('Index/pdShow');
    	$adminUrl=$_SERVER['HTTP_HOST'].rtrim(dirname($_SERVER['PHP_SELF']));
		header("Location: http://".$adminUrl.$_url);
    }
    /**
     * 产品展示
     */
    public function pdShow(){
    	//取得产品展示信息
    	$_group=$_REQUEST["group"];
    	$group=new Model("image_group");
    	$grupData=$group->order('g_id asc')->select();
    	$use_ig=$_group;
    	$outGroup=array();
    	$i=0;
	   	 if($grupData && is_array($grupData) && count($grupData)){
		    		foreach ($grupData as $bal){
		    			$outGroup[$i]['g_id']=$bal['g_id'];
		    			if($_SESSION["lan"]=='en'){
		    				$outGroup[$i]['g_name_cn']=$bal['g_name_en'];
		    			}
		    			else{
		    				$outGroup[$i]['g_name_cn']=$bal['g_name_cn'];
		    			}
		    			
		    			$outGroup[$i]['g_created_time']=$bal['g_created_time'];
		    			$i++;
		    		}
	   	 }
    	
    	if(!$_group){
	    	
	    		foreach ($grupData as $val){
	    			$use_ig=$val["g_id"];
	    			break;
	    		}
	    }
    	
    	$images=new Model("image");
    	//$query["g_id"]=array("in",$use_ig);
    	//$imgData=$images->where($query)->select();
    	$imgData=$images->select();
    	$outImgData=array();
    	if($imgData && is_array($imgData) && count($imgData)){
    		foreach ($imgData as $row){
    			if($row["g_id"]){
    				$g_id=explode(',', $row["g_id"]);
    				if(in_array($use_ig, $g_id)){
    					$outImgData[]=$row;
    				}
    				
    			}
    		}
    	}
    	/*$this->assign('cp_jj',i18n::load()->trans('公司简介'));
    	$this->assign('sv_jj',i18n::load()->trans('服务内容'));
    	$this->assign('tel_jj',i18n::load()->trans('联系我们'));
    	$this->assign('pd_jj',i18n::load()->trans('产品展示'));
    	*/
    	
    	$out=$this->getMenu();
    	$this->assign("menu",$out);
    	$current=$this->getCurrentM(2);
    	$this->assign('pd_jj',$current["name"]);
  		$this->assign('grupData',$outGroup);
  		$this->assign('imgDatas',$outImgData);
  		$this->assign("mNum",2);
    	$this->display("pdShow");
    }
    /**
     * 公司简介
     */
    public function cp(){
    	/*$this->assign('cp_jj',i18n::load()->trans('公司简介'));
    	
    	$this->assign('sv_jj',i18n::load()->trans('服务内容'));
    	$this->assign('tel_jj',i18n::load()->trans('联系我们'));
    	$this->assign('pd_jj',i18n::load()->trans('产品展示'));
    	$this->assign('cp_jj_nr',i18n::load()->trans('公司简介内容'));
    	*/
    	$current=$this->getCurrentM(1);
    	$this->assign('cp_jj',$current["name"]);
    	$this->assign('cp_jj_nr',$current["text"]);
    	$out=$this->getMenu();
    	$this->assign("menu",$out);
    	$this->assign("mNum",1);
    	$isEn='n';
    	if($_SESSION["lan"]=='en'){
    		$isEn='y';
    	}
    	$this->assign('isEn',$isEn);
    	$this->display("cp");
    }
    /**
     * 服务内容
     */
    public function sv(){
    	
    	/*$this->assign('cp_jj',i18n::load()->trans('公司简介'));
    	$this->assign('sv_jj',i18n::load()->trans('服务内容'));
    	$this->assign('tel_jj',i18n::load()->trans('联系我们'));
    	$this->assign('pd_jj',i18n::load()->trans('产品展示'));
    	$this->assign('cp_jj_nr',i18n::load()->trans('服务内容内容'));
    	*/
    	$out=$this->getMenu();
    	$this->assign("menu",$out);
    	
    	$current=$this->getCurrentM(4);
    	$this->assign('sv_jj',$current["name"]);
    	$this->assign('cp_jj_nr',$current["text"]);
    	$this->assign("mNum",4);
    	$this->display("sv");
    }
    /**
     * 联系我们
     */
    public function tel(){
    	
    	/*$this->assign('cp_jj_nr',i18n::load()->trans('联系我们内容'));
    	$this->assign('cp_jj',i18n::load()->trans('公司简介'));
    	$this->assign('sv_jj',i18n::load()->trans('服务内容'));
    	$this->assign('tel_jj',i18n::load()->trans('联系我们'));
    	$this->assign('pd_jj',i18n::load()->trans('产品展示'));
    	*/
    	$out=$this->getMenu();
    	$this->assign("menu",$out);
    	
    	$current=$this->getCurrentM(5);
    	$this->assign('tel_jj',$current["name"]);
    	$this->assign('tel_jj_nr',$current["text"]);
    	$this->assign("mNum",5);
    	$this->display("tel");
    }
    /**
     * 墙体彩绘
     * Enter description here ...
     */
    public function qiangti(){
    	$out=$this->getMenu();
    	$this->assign("menu",$out);
    	
    	$current=$this->getCurrentM(3);
    	$this->assign('qt_jj',$current["name"]);
    	$image=new Model("image");
    	$data=$image->where('img_bz=2')->select();
    	$this->assign('images',$data);
    	$this->assign("mNum",3);
    	$this->display("qiangti");
    }
	/**
	 * 得到墙体彩绘的图片及说明
	 * Enter description here ...
	 */
	public function getImgContent(){
		$m_id=$_REQUEST["pid"];
		$lan=$_SESSION["lan"];
		$rev=array("url"=>"","text"=>"");
		$image=new Model("image");
		$query["pid"]=$m_id;
		$datas=$image->where($query)->select();
		if(is_array($datas) && count($datas)){
			$data=$datas[0];
			
			$rev["pid"]=$data["pid"];
			$rev["url"]=$data["img_url"];
			if($lan=="en"){
				$rev["text"]=unserialize($data["img_shuoming_en"]);
			}else{
				$rev["text"]=unserialize($data["img_shuoming"]);
			}
			
		}
		echo json_encode($rev);
		exit;
	}
    private function getMenu(){
    	$menu=new Model("menu");
    	$ms=$menu->order("m_num asc")->select();
    	$out=array();
    	$i=0;
    	if(count($ms)){
    		foreach ($ms as $val){
    			$out[$i]["m_id"]=$val["m_id"];
    			$out[$i]["id"]=$val["m_num"];
    			$out[$i]["url"]=$val["m_q_url"];
    			if($_SESSION["lan"]=='en'){
    				$out[$i]["name"]=$val["m_name_en"];
    				$out[$i]["text"]=$val["m_text_en"];
    			}else{
    				$out[$i]["name"]=$val["m_name_cn"];
    				$out[$i]["text"]=$val["m_text_cn"];
    			}
    			$i++;
    		}
    	}
    	$_SESSION["MENUS"]=$out;
    	return $out;
    }
    private function getCurrentM($id){
    	$menu=new Model("menu");
    	$data=$menu->where('m_id='.$id)->select();
    	if($_SESSION["lan"]=='en'){
    		$out=array("name"=>$data[0]["m_name_en"],'text'=>stripslashes($data[0]["m_text_en"]));
    	}else{
    		$out=array("name"=>$data[0]["m_name_cn"],'text'=>stripslashes($data[0]["m_text_cn"]));
    	}
    	return $out;
    }
    private function  cut_str1($string, $sublen, $start = 0, $code = 'UTF-8')
	{
	    if($code == 'UTF-8')
	    {
	        $pa = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/";
	        preg_match_all($pa, $string, $t_string);
	
	        if(count($t_string[0]) - $start > $sublen) return join('', array_slice($t_string[0], $start, $sublen))."...";
	        return join('', array_slice($t_string[0], $start, $sublen));
	    }
	    else
	    {
	        $start = $start*2;
	        $sublen = $sublen*2;
	        $strlen = strlen($string);
	        $tmpstr = '';
	
	        for($i=0; $i< $strlen; $i++)
	        {
	            if($i>=$start && $i< ($start+$sublen))
	            {
	                if(ord(substr($string, $i, 1))>129)
	                {
	                    $tmpstr.= substr($string, $i, 2);
	                }
	                else
	                {
	                    $tmpstr.= substr($string, $i, 1);
	                }
	            }
	            if(ord(substr($string, $i, 1))>129) $i++;
	        }
	        if(strlen($tmpstr)< $strlen ) $tmpstr.= "...";
	        return $tmpstr;
	    }
	}
 	/**
     * 招聘
     */
    public function zp(){
    	$out=$this->getMenu();
    	$this->assign("menu",$out);
    	
    	$current=$this->getCurrentM(6);
    	$this->assign('zp_jj',$current["name"]);
    	$this->assign('zp_jj_nr',$current["text"]);
    	$this->assign("mNum",6);
    	$this->display("zp");
    }
    
}